package com.shu.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.shu.utils.JdbcUtils;

public class TestDB {
	
	public static void main(String[] args) throws Exception {
		
		String driver = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://192.168.1.10:3306/mzj-xpipe?useUnicode=true&characterEncoding=utf-8&autoReconnect=true";
		String userName = "root";
		String passwd = "root";
		Connection con = JdbcUtils.getConnection(driver, url, userName, passwd);
		
		String driver1 = "com.mysql.jdbc.Driver";
		String url1 = "jdbc:mysql://192.168.1.16:3306/mzj-manager?useUnicode=true&characterEncoding=utf-8&autoReconnect=true";
		String userName1 = "root";
		String passwd1 = "root";
		Connection con1 = JdbcUtils.getConnection(driver1, url1, userName1, passwd1);
		
		for(int i=0;i<100;i++) {
			System.out.println(i);
			if(i % 2 == 1) {
				TestDB.test1(con,i+"", "left"+i);
			}else {
				TestDB.test2(con1,i+"", "right"+i);
			}
		}

	}
	
	public static void test1(Connection conn,String id,String name) throws Exception {
		
		 Statement stmt = conn.createStatement();
         //新增一条数据
         stmt.executeUpdate("INSERT INTO t_test (id, name) VALUES ('"+id+"', '"+name+"')");
	}
	
	public static void test2(Connection conn,String id,String name) throws Exception {
		
		 Statement stmt = conn.createStatement();
         //新增一条数据
         stmt.executeUpdate("INSERT INTO t_test (id, name) VALUES ('"+id+"', '"+name+"')");
	}

}
